---
layout: m1x_rest
title: Product Categories
---


<ul class="introduction-menu">
    <li><a href='#RESTAPI-Resource-ProductCategories-RESTAPI-ProductCategories'>REST API: Product Categories</a>
    <ul>
        <li><a href='#RESTAPI-Resource-ProductCategories-URI--products-productid-categories'>URI: /products/productid/categories</a>
        <ul>
            <li><a href='#RESTAPI-Resource-ProductCategories-HTTPMethod-GET'>HTTP Method: GET</a></li>
            <li><a href='#RESTAPI-Resource-ProductCategories-HTTPMethod-POST'>HTTP Method: POST</a></li>
        </ul>
        </li>
        <li><a href='#RESTAPI-Resource-ProductCategories-URI--products-productid-categories-categoryid'>URI: /products/productid/categories/categoryid</a>
        <ul>
            <li><a href='#RESTAPI-Resource-ProductCategories-HTTPMethod-DELETE'>HTTP Method: DELETE</a></li>
        </ul>
        </li>
        <li><a href='#RESTAPI-Resource-ProductCategories-PossibleHTTPStatusCodes'>Possible HTTP Status Codes</a></li>
    </ul>
    </li>
</ul>


<h3><a name="RESTAPI-Resource-ProductCategories-RESTAPI-ProductCategories"></a>REST API: Product Categories</h3>

<h4><a name="RESTAPI-Resource-ProductCategories-URI--products-productid-categories"></a>URI: /products/productid/categories</h4>

<p>Allows you to retrieve information about assigned categories, assign, and unassign a category from/to a product.</p>

<p><b>URL Structure</b>: <a href="http://magentohost/api/rest/products/productid/categories">http://magentohost/api/rest/products/productid/categories</a><br/>
<b>Version</b>: 1</p>

<h5><a name="RESTAPI-Resource-ProductCategories-HTTPMethod-GET"></a>HTTP Method: GET</h5>

<p><b>描述</b>: Allows you to retrieve information about categories assigned to the specified product.</p>


<p><b>Authentication</b>: Admin, Customer<br/>
<b>Default Format</b>: JSON<br/>
<b>Parameters</b>:<br/>
<em>No Parameters</em></p>

<p><b>Example:</b></p>

<div class='panelMacro'><table class='infoMacro'><tr><td>GET <a href="http://magentohost/api/rest/products/8/categories">http://magentohost/api/rest/products/8/categories</a></td></tr></table></div>

<p><b>Response Body:</b></p>
<div class="panel" style="border-width: 1px;"><div class="panelContent">
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">{
     category_id: 8
}</pre>
		</div>
</div></div>
</div></div>



<h5><a name="RESTAPI-Resource-ProductCategories-HTTPMethod-POST"></a>HTTP Method: POST</h5>

<p><b>描述</b>: Allows you to assign a category to a specified product.</p>


<p><b>Authentication</b>: Admin<br/>
<b>Default Format</b>: JSON<br/>
<b>Parameters</b>:</p>


<table><tbody>
<tr>
<th> Name </th>
<th> Description </th>
<th> Required </th>
<th> Type </th>
<th> Example Value </th>
</tr>
<tr>
<td> category_id </td>
<td> The category ID </td>
<td> required </td>
<td> int </td>
<td> 2 </td>
</tr>
</tbody></table>




<p><b>Example:</b></p>

<div class='panelMacro'><table class='infoMacro'><tr><td>POST <a href="http://magentohost/api/rest/products/8/categories">http://magentohost/api/rest/products/8/categories</a></td></tr></table></div>

<p><b>Request Body:</b></p>
<div class="panel" style="border-width: 1px;"><div class="panelContent">
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<div id="root">
		<pre class="theme: Default; brush: java; gutter: false">{
"category_id":"2"
}</pre>
		</div>
</div></div>
</div></div>

<p>As a result, the category with ID equal to 2 will be assigned to the specified product.</p>


<h4><a name="RESTAPI-Resource-ProductCategories-URI--products-productid-categories-categoryid"></a>URI: /products/productid/categories/categoryid</h4>

<h5><a name="RESTAPI-Resource-ProductCategories-HTTPMethod-DELETE"></a>HTTP Method: DELETE</h5>

<p><b>描述</b>: Allows you to unassign a category from a specified product.</p>


<p><b>Authentication</b>: Admin<br/>
<b>Default Format</b>: JSON<br/>
<b>Parameters</b>:<br/>
<em>No Parameters</em></p>

<p><b>Example:</b></p>

<div class='panelMacro'><table class='infoMacro'><tr><td>DELETE <a href="http://magentohost/api/rest/products/8/categories/2">http://magentohost/api/rest/products/8/categories/2</a></td></tr></table></div>


<h4><a name="RESTAPI-Resource-ProductCategories-PossibleHTTPStatusCodes"></a>Possible HTTP Status Codes</h4>


<table><tbody>
<tr>
<th> Status Code </th>
<th> Message </th>
<th> Description </th>
</tr>
<tr>
<td> 400 </td>
<td> Product &lt;product ID&gt; is already assigned to category &lt;category ID&gt; </td>
<td> The message is returned when the required category is already assigned to the product </td>
</tr>
<tr>
<td> 400 </td>
<td> Category not found </td>
<td> The specified category is not found </td>
</tr>
<tr>
<td> 405 </td>
<td> Resource method not implemented yet </td>
<td> The specified method is not implemented yet </td>
</tr>
</tbody></table>


<?php include(__ROOT__ . 'footer.php'); ?>		    
